USE [master]
GO

-- =============================================
-- Author:       Justin Wallace Saunders
-- Create date:  20090628
-- Description:  %TargetDatabaseName% Database Detacher
-- Information:  http://msdn.microsoft.com/en-us/library/ms188031.aspx
-- =============================================
IF EXISTS (SELECT * FROM sys.databases WHERE [Name] = N'%TargetDatabaseName%')
BEGIN
    EXEC sp_detach_db N'%TargetDatabaseName%', 'true', 'false'
END
GO